package guoanmaker.personal.business.service;

import java.util.Date;
import java.util.List;
import java.util.Optional;

import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.aliyun.oss.OSSClient;

import guoanmaker.personal.business.dao.PersonalUserDao;
import guoanmaker.personal.business.model.ApprReturn;
import guoanmaker.personal.business.model.PersonalCode;
import guoanmaker.personal.business.model.PersonalUser;
import guoanmaker.personal.business.model.PersonalUserLandLog;
import guoanmaker.personal.business.model.ReturnResult;
import guoanmaker.personal.business.model.Uservo;
import guoanmaker.personal.business.modelnobind.PersonalUserForUser;
import guoanmaker.personal.business.repository.PersonalCodeRepository;
import guoanmaker.personal.business.repository.PersonalUserLandLogRepository;
import guoanmaker.personal.business.repository.PersonalUserRepository;
import guoanmaker.personal.helper.common.abstractobj.ApiController;
import guoanmaker.personal.helper.common.util.Forbidener;
import guoanmaker.personal.helper.common.util.JasyptHelper;
import guoanmaker.personal.helper.common.util.OSSUnitHelper;
import guoanmaker.personal.helper.common.util.SystemHelper;
import redis.clients.jedis.Jedis;


/**
 * 
* @ClassName: PersonalUserService 
* @Description: 用户service
* @author Yvonne_MGL
* @date 2017年7月6日 下午3:58:10 
*  
 */
@Service
public class PersonalUserService implements PersonalUserServiceInterface{
	private final PersonalUserRepository personalUserRepository;
	private final PersonalCodeRepository personalCodeRepository;
	private final PersonalCodeService personalCodeService;
	private final PersonalUserDao personalUserDao;
	private final PersonalUserCouponService personalUserCouponService;
	private final PersonalUserLandLogRepository personalUserLandLogRepository;
	private final Forbidener forbidener;
	
	  @Autowired  
	  private  HttpServletRequest request;
	
	@Autowired
    public PersonalUserService(PersonalUserRepository personalUserRepository,PersonalCodeRepository personalCodeRepository,PersonalCodeService personalCodeService,PersonalUserDao personalUserDao,PersonalUserCouponService personalUserCouponService,PersonalUserLandLogRepository personalUserLandLogRepository,Forbidener forbidener) {
        this.personalUserRepository = personalUserRepository;
        this.personalCodeRepository=personalCodeRepository;
        this.personalCodeService=personalCodeService;
        this.personalUserDao=personalUserDao;
        this.personalUserCouponService=personalUserCouponService;
        this.personalUserLandLogRepository=personalUserLandLogRepository;
        this.forbidener=forbidener;
    }
	
	public Forbidener getForbidener(){
		return forbidener;
	}
	
	public PersonalUserDao getPersonalUserDao() {
        return personalUserDao;
    }
	
	public PersonalCodeService getPersonalCodeService() {
        return personalCodeService;
    }
    
    public PersonalCodeRepository getPersonalCodeRepository() {
        return personalCodeRepository;
    }
    
    public PersonalUserRepository getPersonalUserRepository() {
        return personalUserRepository;
    }
    
    public PersonalUserCouponService getpersonalUserCouponService(){
    	return personalUserCouponService;
    }
    
    public PersonalUserLandLogRepository getPersonalUserLandLogRepository(){
    	return personalUserLandLogRepository;
    }

    @Override
    public Optional<PersonalUser> getByUsername(String username) {
        return this.personalUserRepository.findByUsername(username);
    }
    
    /**
     * 
    * @Description: 注册用户
	* @param username 用户名,即手机号
	* @param password 密码
	* @param code 验证码
    * @author Yvonne_MGL 
    * @date 2017年7月6日 下午3:58:43     
    * @return ReturnResult    
    * @throws 
     */
    @Transactional
    public ReturnResult registeredUser(String username,String password,String code,String createType){
    	ReturnResult returnResult=new ReturnResult();
    	List<PersonalUser> personalUserList=personalUserRepository.findUserByUsername(username);
    	if(personalUserList!=null&&personalUserList.size()>0){
    		returnResult.setKey("error");
    		returnResult.setValue("用户已存在");
    	}else{
    		List<PersonalCode> list=personalCodeRepository.findCodeByTelephone(username);
    		if(list==null||list.size()==0){
    			returnResult.setKey("error");
        		returnResult.setValue("请先获取验证码");
    		}else{
    			PersonalCode personalCode=list.get(0);
    			if(personalCode.getCode()!=null&&code!=null&&personalCode.getCode().equals(code)){
    				if(password==null||password.equals("")){
    					returnResult.setKey("error");
                		returnResult.setValue("密码不能为空");
    				}else if(username==null||username.equals("")){
    					returnResult.setKey("error");
                		returnResult.setValue("用户名不能为空");
    				}else{
    					PersonalUser personalUser=new PersonalUser();
                		personalUser.setUsername(username);
                		personalUser.setPassword(JasyptHelper.encrypt(password, ApiController.PASSWORD_SALT));
                		personalUser.setCreateTime(new Date());
                		personalUser.setNickname(SystemHelper.getNickName());
                		personalUser.setCreateType(createType);
                		personalUserRepository.save(personalUser);
                		personalCodeRepository.delete(personalCode.getId());
                		personalUserCouponService.savePersonalUserCoupons(personalUser);
                		returnResult.setKey("success");
                		returnResult.setValue("注册成功");
    				}
    				
    			}else{
    				returnResult.setKey("error");
            		returnResult.setValue("验证码不正确");
    			}
    			
    		}
    		
    	}
    	
    	return returnResult;
    }
    
    /**
     * 
    * @Description: 验证用户名密码 
	* @param username 用户名
	* @param password 密码
    * @author Yvonne_MGL 
    * @date 2017年7月6日 下午3:58:57     
    * @return ReturnResult    
    * @throws 
     */
    @Transactional
    public ReturnResult verify(String username,String password,String landType){
    	ReturnResult returnResult=new ReturnResult();
    	List<PersonalUser> personalUserList=personalUserRepository.findUserByUsername(username);
    	if(personalUserList!=null&&personalUserList.size()>0){
    		PersonalUser personalUser=personalUserList.get(0);
    		if(personalUser.getIsFreeze()!=null&&personalUser.getIsFreeze().equals("1")){
    			returnResult.setKey("error");
    			returnResult.setValue("账号被冻结");
    		}else{
    			if(personalUser.getWrongBout()>=3&&SystemHelper.getLessTwoHourTime().before(personalUser.getWrongTime())){
    				returnResult.setKey("error");
        			returnResult.setValue("验证错误次数过多被冻结,请2小时后重试");
    			}else{
    				if(personalUser.getWrongBout()>=3){
    					personalUser.setWrongBout(0);
    				}
    				if(personalUser.getPassword()!=null&&(!personalUser.getPassword().equals(""))){
	        			if(JasyptHelper.decrypt(personalUser.getPassword(), ApiController.PASSWORD_SALT).equals(password)){
	            			returnResult.setKey("success");
	            			returnResult.setValue(personalUser.getId());
	            			personalUser.setWrongBout(0);
	            			personalUser.setLastLandTime(new Date());
	            			
	            			PersonalUserLandLog landLog=personalUserDao.findByLandLog(username, landType);
	            			if(landLog==null){
	            				landLog=new PersonalUserLandLog();
	            				landLog.setUsername(username);
		            			landLog.setLandType(landType);
		            			landLog.setLandCount(1);
	            			}else{
	            				landLog.setLandCount(landLog.getLandCount()+1);
	            			}
	            			landLog.setLandTime(new Date());
	            			
	            			personalUserLandLogRepository.save(landLog);
	            			
	            		}else{
	            			returnResult.setKey("error");
	            			returnResult.setValue("密码错误");
	            			personalUser.setWrongBout(personalUser.getWrongBout()+1);
	            			personalUser.setWrongTime(new Date());
	            		}
	        		}else{
	        			returnResult.setKey("error");
	        			returnResult.setValue("密码错误");
	        			personalUser.setWrongBout(personalUser.getWrongBout()+1);
	        			personalUser.setWrongTime(new Date());
	        		}
    				personalUserRepository.save(personalUser);
    			}
    			
    		}
    	}else{
    		returnResult.setKey("error");
			returnResult.setValue("用户未注册");
    	}
    	return returnResult;
    }
    
    @Override
	public PersonalUser insertUser(PersonalUser personalUser) {
		return this.personalUserRepository.save(personalUser);
	}
    
    @Transactional
    public int updatetset(PersonalUser personalUser){
    	String username=personalUser.getUsername();
    	String  wechatnickname  =  personalUser.getWechatnickname();
    	String wechatportraitN= personalUser.getWechatportraitN();
    	Date createTime =personalUser.getCreateTime();
    	return personalUserRepository.updatePersonalUserBynp(wechatnickname, createTime, wechatportraitN, username);
    }

	/*@Override
	public PersonalUser loginUserThird(HttpSession session, PersonalUser personalUser) {
		
		ArrayList<PersonalUser>  userNew=(ArrayList<PersonalUser>) personalUserRepository.loginSelectThird(personalUser);
		//如果用户设置了头像，加载头像地址
				if(userNew!=null&&userNew.size()>0){
					PersonalUser userlogin = userNew.get(0);
					if(null!=userlogin&&null!=userlogin.getPortrait()&&!("".equals(userlogin.getPortrait()))){
						ArtSysParam artSysParam = new ArtSysParam();
						artSysParam.setArtparamId("60002");
						artSysParam = artSysParamMapper.selectByParamid(artSysParam);
						userlogin.setUseravatarlocation(ArtSysConstant.getAddressParam("artAuctionPicServerAddress") 
								                     + artSysParam.getArtparamName() 
								                     + userlogin.getUseravatarlocation());
						System.out.println(session.getId());
						CheckLoginRepeat.LoginUser(userlogin.getId(), session.getId());
						session.setAttribute("LoginUser", userlogin);	
					}
					return userlogin;
					
				}
		
		return null;
	}*/
    
    /**
     * 
    * @Description: 重置密码
	* @param username 用户名
	* @param password 密码
	* @param code 验证码
    * @author Yvonne_MGL 
    * @date 2017年7月6日 下午3:59:21     
    * @return ReturnResult    
    * @throws 
     */
    @Transactional
    public ReturnResult changePassword(String username,String password,String code){
    	ReturnResult returnResult=new ReturnResult();
    	if(password==null||password.equals("")){
    		returnResult.setKey("error");
			returnResult.setValue("密码不能为空");
    	}else{
    		List<PersonalCode> list=personalCodeRepository.findCodeByTelephone(username);
    		if(list==null||list.size()==0){
    			returnResult.setKey("error");
        		returnResult.setValue("请先获取验证码");
    		}else{
    			PersonalCode personalCode=list.get(0);
    			if(personalCode.getCode()!=null&&code!=null&&personalCode.getCode().equals(code)){
    				List<PersonalUser> personalUserList=personalUserRepository.findUserByUsername(username);
    	        	if(personalUserList!=null&&personalUserList.size()>0){
    	        		PersonalUser personalUser=personalUserList.get(0);
    	        		personalUser.setPassword(JasyptHelper.encrypt(password, ApiController.PASSWORD_SALT));
    	        		personalUserRepository.save(personalUser);
    	        		personalCodeRepository.delete(personalCode.getId());
    	        		returnResult.setKey("success");
    	        		returnResult.setValue("修改密码成功");
    	        	}else{
    	        		returnResult.setKey("error");
    	    			returnResult.setValue("用户未注册");
    	        	}
    			}else{
    				returnResult.setKey("error");
            		returnResult.setValue("验证码不正确");
    			}
    	
    		}
    	}
    	return returnResult;
    }
    
    /**
     * 
    * @Description: 修改密码 
    * @param userid 用户id
    * @param oldPassword 旧密码
    * @param newPassword 新密码
    * @param @return
    * @author Yvonne_MGL 
    * @date 2017年8月28日 下午1:55:58     
    * @return ReturnResult    
    * @throws 
     */
    @Transactional
    public ReturnResult changeUserPassword(String userid,String oldPassword,String newPassword){
    	ReturnResult returnResult=new ReturnResult();
    	PersonalUser personalUser=personalUserRepository.findOne(userid);
    	if(newPassword==null||newPassword.equals("")){
    		returnResult.setKey("error");
    		returnResult.setValue("密码不允许为空");
    	}else{
    		if(personalUser==null){
    			returnResult.setKey("error");
        		returnResult.setValue("用户不存在");
    		}else{
    			if(JasyptHelper.decrypt(personalUser.getPassword(), ApiController.PASSWORD_SALT).equals(oldPassword)){
    				personalUser.setPassword(JasyptHelper.encrypt(newPassword, ApiController.PASSWORD_SALT));
	        		personalUserRepository.save(personalUser);
	        		returnResult.setKey("success");
	        		returnResult.setValue("修改密码成功");
    			}else{
    				returnResult.setKey("error");
            		returnResult.setValue("旧密码不正确");
    			}
    		}
    	}
    	return returnResult;
    }
    
    /**
     * 
    * @Description: 修改个人资料
	* @param userid 用户id
	* @param portraitFile  头像图片
	* @param nickname 昵称
	* @param birthday 生日
	* @param name 姓名
    * @author Yvonne_MGL 
    * @date 2017年7月6日 下午3:59:41     
    * @return PersonalUserForUser    
    * @throws 
     */
    @Transactional
    public PersonalUserForUser updateUser(String userid,MultipartFile portraitFile,String nickname,String birthday,String name){
    	
    	PersonalUserForUser user=personalUserDao.findById(userid);
    	
    	if(user!=null){
    		PersonalUser personalUser=personalUserRepository.findOne(userid);
    		if(nickname!=null&&!nickname.equals("")){
    			user.setNickname(nickname);
    			personalUser.setNickname(nickname);
    		}
    		if(birthday!=null&&!birthday.equals("")){
    			user.setBirthday(birthday);
        		personalUser.setBirthday(birthday);
    		}
    		if(name!=null&&!name.equals("")){
    			user.setName(name);
        		personalUser.setName(name);
    		}
    		
    		if(portraitFile!=null&&portraitFile.getSize()>0){
    			String fileName=portraitFile.getOriginalFilename();
    	    	String fileExtension = fileName.substring(fileName.lastIndexOf("."));
    			OSSClient client = OSSUnitHelper.getOSSClient(); 
    			OSSUnitHelper.uploadObjectOSS(client, portraitFile,ApiController.PORTRAINT_URL+ user.getUsername()+"/",user.getUsername()+fileExtension); 
    			String url=OSSUnitHelper.getUrl(client, ApiController.PORTRAINT_URL+ user.getUsername()+"/", user.getUsername()+fileExtension);
    			user.setPortraitName(user.getUsername()+fileExtension);
    			personalUser.setPortraitName(user.getUsername()+fileExtension);
    			String urlstr=url.substring(0,url.indexOf("?"))+"?uploadTime="+new Date().getTime();
    			String uString=urlstr.replaceAll("http", "https");
    			user.setPortrait(uString);
    			personalUser.setPortrait(uString);
    		}
    		personalUserRepository.save(personalUser);
    	}
    	return user;
    }
    
    /**
     * 
    * @Description: 修改个人资料
	* @param userid 用户id
	* @param portraitFile  头像图片
	* @param nickname 昵称
	* @param birthday 生日
	* @param name 姓名
    * @author Yvonne_MGL 
    * @date 2017年7月6日 下午3:59:41     
    * @return PersonalUserForUser    
    * @throws 
     */
    @Transactional
    public PersonalUserForUser updateUser(String userid,String portraitFile,String nickname,String birthday,String name){
    	
    	PersonalUserForUser user=personalUserDao.findById(userid);
    	
    	if(user!=null){
    		PersonalUser personalUser=personalUserRepository.findOne(userid);
    		if(nickname!=null&&!nickname.equals("")){
    			user.setNickname(nickname);
    			personalUser.setNickname(nickname);
    		}
    		if(birthday!=null&&!birthday.equals("")){
    			user.setBirthday(birthday);
        		personalUser.setBirthday(birthday);
    		}
    		if(name!=null&&!name.equals("")){
    			user.setName(name);
        		personalUser.setName(name);
    		}
    		
    		if(portraitFile!=null&&!portraitFile.equals("")){
    			if(!portraitFile.startsWith("https")){
    				String uString=portraitFile.replaceAll("http", "https");
        			user.setPortrait(uString);
        			personalUser.setPortrait(uString);
        		}
    			}else{
    				user.setPortrait(portraitFile);
    				personalUser.setPortrait(portraitFile);
    			}
    		personalUserRepository.save(personalUser);
    	}
    	return user;
    }
    
    /**
     * 
    * @Description: 查询用户资料 
	* @param userid 用户id
    * @author Yvonne_MGL 
    * @date 2017年7月6日 下午4:00:01     
    * @return PersonalUserForUser    
    * @throws 
     */
    public PersonalUserForUser findById(String userid){
    	return personalUserDao.findById(userid);
    }
    
    /**
     * 
    * @Description: 发送验证码
	* @param telephone 电话
	* @param isuser 判断用户存在发验证码传1,用户不存在发验证码传2,存不存在都发传0
    * @param @throws Exception
    * @author Yvonne_MGL 
    * @date 2017年7月6日 下午4:00:16     
    * @return ReturnResult    
    * @throws 
     */
    @Transactional
    public ReturnResult sendVerificationCode(String telephone,String isuser) throws Exception{
    	ReturnResult returnResult = new ReturnResult();
    	
    	 
        String ipString=SystemHelper.getIp2(request);
        System.err.println("IP为："+ipString);
        if(forbidener.check(ipString)){
        	if(isuser!=null&&isuser.equals("1")){
        		List<PersonalUser> userlist=personalUserRepository.findUserByUsername(telephone);
        		if(userlist==null||userlist.size()==0){
        			returnResult.setKey("error");
            		returnResult.setValue("用户不存在");
        		}else{
        			returnResult=personalCodeService.sendCode(telephone);
        		}
        	}else if(isuser!=null&&isuser.equals("2")){
        		List<PersonalUser> userlist=personalUserRepository.findUserByUsername(telephone);
        		if(userlist!=null&&userlist.size()>0){
        			returnResult.setKey("error");
            		returnResult.setValue("用户已存在");
        		}else{
        			returnResult=personalCodeService.sendCode(telephone);
        		}
        	}else{
        		returnResult=personalCodeService.sendCode(telephone);
        	}
        	System.err.println(ipString+":成功");
        }else{
        	returnResult.setKey("error");
    		returnResult.setValue("此IP短时间内发送验证码次数过多，已封禁");
    		System.err.println(ipString+":失败");
        }
    	
    	
		return returnResult;
    }
    
    /**
     * 
    * @Description: 将用户设置为服务商 
	* @param userid 用户id
    * @author Yvonne_MGL 
    * @date 2017年7月6日 下午4:00:31     
    * @return ReturnResult    
    * @throws 
     */
    @Transactional
    public ReturnResult beProvider(String userid,String state){
    	ReturnResult returnResult=new ReturnResult();
    	PersonalUser personalUser=personalUserRepository.findOne(userid);
    	if(personalUser==null){
    		returnResult.setKey("error");
			returnResult.setValue("用户未注册");
			
    	}else{
    		if(state==null){
    			returnResult.setKey("error");
    			returnResult.setValue("操作状态不正确");
    		}else{
    			if(state.equals("1")){
    				if(personalUser.getIsProvider()!=null&&(personalUser.getIsProvider().equals("1")||personalUser.getIsProvider().equals("2")||personalUser.getIsProvider().equals("4"))){
    					returnResult.setKey("error");
    	    			returnResult.setValue("操作状态不正确");
    				}else{
    					personalUser.setIsProvider("1");
    					personalUser.setApplyForProviderTime(new Date());
    					personalUserRepository.save(personalUser);
    					returnResult.setKey("success");
    					returnResult.setValue("用户已申请成为服务商");
    				}
    			}else if(state.equals("2")){
    				if(!personalUser.getIsProvider().equals("1")||!personalUser.getIsProvider().equals("4")){
    					returnResult.setKey("error");
    	    			returnResult.setValue("操作状态不正确");
    				}else{
    					personalUser.setIsProvider("2");
    					personalUser.setIsProviderTime(new Date());
    					personalUserRepository.save(personalUser);
    					returnResult.setKey("success");
    					returnResult.setValue("成为服务商审核通过");
    				}
    			}else if(state.equals("3")){
    				if(!personalUser.getIsProvider().equals("1")){
    					returnResult.setKey("error");
    	    			returnResult.setValue("操作状态不正确");
    				}else{
    					personalUser.setIsProvider("3");
    					personalUserRepository.save(personalUser);
    					returnResult.setKey("success");
    					returnResult.setValue("成为服务商审核失败");
    				}
    			}else if(state.equals("4")){
    				if(!personalUser.getIsProvider().equals("2")){
    					returnResult.setKey("error");
    	    			returnResult.setValue("操作状态不正确");
    				}else{
    					personalUser.setIsProvider("4");
    					personalUserRepository.save(personalUser);
    					returnResult.setKey("success");
    					returnResult.setValue("冻结服务商成功");
    				}
    			}else{
    				returnResult.setKey("error");
	    			returnResult.setValue("操作状态不正确");
    			}
    		}
    		
    	}
    	return returnResult;
    }

	@Override
	public List<PersonalUser> loginUserThird(String openId) {
		
		return personalUserRepository.findUserByWechatopenid(openId);
	}

	@Override
	public List<PersonalUser> selectByUsernameandOpenid(String openId, String username) {
		
		return personalUserRepository.findUserByWopenidorp(openId, username);
	}

	@Override
	public List<PersonalUser> findUsername(String username) {
		
		return personalUserRepository.findUsername(username);
	}
	
	@Transactional
	public  void updatePersonalUser(String username){
		
		
		
		
	}

	@Override
	public List<PersonalUser> loginqqUserThird(String qqopenId) {
		return personalUserRepository.findUserByqqopenid(qqopenId);
	}

	@Override
	public List<PersonalUser> loginweiboUserThird(String wbopenId) {
		return personalUserRepository.findUserByWeibouuid(wbopenId);
	}

	


    
    /**
     * 
   * @Description: 手机快捷登陆
	* @param username 用户名
	* @param code 验证码
    * @author Yvonne_MGL 
    * @date 2017年7月6日 下午4:01:05     
    * @return ReturnResult    
    * @throws 
     */
    @Transactional
    public ReturnResult fastLanding(String username,String code,String createType){
    	ReturnResult returnResult=new ReturnResult();
    	List<PersonalCode> list=personalCodeRepository.findCodeByTelephone(username);
		if(list==null||list.size()==0){
			returnResult.setKey("error");
    		returnResult.setValue("请先获取验证码");
		}else{
			PersonalCode personalCode=list.get(0);
			if(personalCode.getCode()!=null&&code!=null&&personalCode.getCode().equals(code)){
	    		List<PersonalUser> personalUserList=personalUserRepository.findUserByUsername(username);
	    		PersonalUser personalUser=null;
	    		String mark="0";
	        	if(personalUserList==null||personalUserList.size()==0){
	        		personalUser=new PersonalUser();
            		personalUser.setUsername(username);
            		personalUser.setCreateTime(new Date());
            		personalUser.setCreateType(createType);
            		mark="1";
	        	}else{
	        		personalUser=personalUserList.get(0);
	        		if(personalUser.getIsFreeze()!=null&&personalUser.getIsFreeze().equals("1")){
	        			returnResult.setKey("error");
	            		returnResult.setValue("请先获取验证码");
	            		return returnResult;
	        		}
	        	}
	        	personalUser.setLastLandTime(new Date());
	        	personalUserRepository.save(personalUser);
	        	personalCodeRepository.delete(personalCode.getId());
	        	if(mark.equals("1")){
	        		personalUserCouponService.savePersonalUserCoupons(personalUser);
	        	}

    			PersonalUserLandLog landLog=personalUserDao.findByLandLog(username, createType);
    			if(landLog==null){
    				landLog=new PersonalUserLandLog();
    				landLog.setUsername(username);
        			landLog.setLandType(createType);
        			landLog.setLandCount(1);
    			}else{
    				landLog.setLandCount(landLog.getLandCount()+1);
    			}
    			landLog.setLandTime(new Date());
    			personalUserLandLogRepository.save(landLog);
	        	
	        	returnResult.setKey("success");
	    		returnResult.setValue(personalUser.getId());
			}else{
				returnResult.setKey("error");
	    		returnResult.setValue("验证码不正确");
			}
		}
		return returnResult;
    }
    
    /**
     * 
    * @Description: 冻结解冻用户 
    * @param userid 用户id
    * @param state 操作状态 0为解冻   1为冻结
    * @param @return
    * @author Yvonne_MGL 
    * @date 2017年7月25日 上午11:14:49     
    * @return ReturnResult    
    * @throws 
     */
    @Transactional
    public ReturnResult freezeOrNotUser(String userid,String state){
    	ReturnResult returnResult=new ReturnResult();
    	PersonalUser personalUser=personalUserRepository.findOne(userid);
    	if(personalUser==null){
    		returnResult.setKey("error");
    		returnResult.setValue("用户不存在");
    	}else{
    		if(state!=null&&(state.equals("0")||state.equals("1"))){
    			personalUser.setIsFreeze(state);
    			personalUserRepository.save(personalUser);
    			returnResult.setKey("success");
    			returnResult.setValue("操作成功");
    		}else{
    			returnResult.setKey("error");
        		returnResult.setValue("状态参数不正确");
    		}
    	}
    	return returnResult;
    }
    
    /**
     * 
    * @Description: 保存用户的渠道来源 
    * @param userid 用户id
    * @param channelSource 来源
    * @param @return
    * @author Yvonne_MGL 
    * @date 2017年11月10日 上午7:11:30     
    * @return ReturnResult    
    * @throws 
     */
    public ReturnResult setSource(String userid,String channelSource){
    	ReturnResult returnResult=new ReturnResult();
    	PersonalUser personalUser=personalUserRepository.findOne(userid);
    	if(personalUser==null){
    		returnResult.setKey("error");
    		returnResult.setValue("用户不存在");
    	}else{
    		if(channelSource!=null&&!channelSource.equals("")){
    			personalUser.setChannelSource(channelSource);
    			personalUserRepository.save(personalUser);
    			returnResult.setKey("success");
    			returnResult.setValue("操作成功");
    		}else{
    			returnResult.setKey("error");
        		returnResult.setValue("渠道参数不正确");
    		}
    	}
    	return returnResult;
    }
    
    /**
	   * 
	   * @param openid           String 类型    ：  微信   微博  qq 的openid
	   * @param type             String 类型     :  1:微信  3：微博  2：qq
	   * @param nickname         String 类型     :  昵称
	   * @param portriname       String 类型     :  头像存储地址
	   * @return
	   */   
   @Transactional 
    public  ApprReturn  thirdLoginforuser(String  openid,String type,String nickname,String portriname){
    	ApprReturn  returnResult=new ApprReturn();
    	if(openid!=null&&!openid.equals("")){
		    String sessionid=request.getSession().getId();
			Jedis jedis=new Jedis("123.56.48.63",6379); 
			jedis.auth("218007");
			jedis.set(sessionid, "1");
		  if(type.equals("1")){
			  List<PersonalUser>	users= personalUserRepository.findUserByWechatopenid(openid);
			  if(users.size()>0){
				    if(users.get(0).getUsername()!=null){
						String ss=jedis.get(users.get(0).getUsername());
						if(ss==null){
							jedis.set(users.get(0).getUsername(), sessionid+",");
						}else{
							jedis.set(users.get(0).getUsername(), ss+sessionid+",");
						}
						jedis.disconnect();
				    }
	  		    	users.get(0).setWechatnickname(nickname);
	  		    	users.get(0).setWechatportrait(portriname);
	  		    	PersonalUser user=	personalUserRepository.save(users.get(0));
	  		    	returnResult.setKey("success");
	  		    	returnResult.setCode("200");
	  		    	Uservo  user1=new Uservo();
	  		    	user1.setUsername(user.getUsername());
	  		    	user1.setPassword(user.getPassword());
	  		    	user1.setWechatnickname(user.getWechatnickname());
	  		    	user1.setWechatopenid(user.getWechatopenid());
	  		    	user1.setWechatportrait(user.getWechatportrait());
	  		    	user1.setWeibonickname(user.getWeibonickname());
	  		    	user1.setWeiboportrait(user.getWeiboportrait());
	  		    	user1.setWeibouuid(user.getWeibouuid());
	  		    	user1.setQqnickname(user.getQqnickname());
	  		    	user1.setQqopenid(user.getQqopenid());
	  		    	user1.setQqportrait(user.getQqportrait());
	  		    	user1.setId(user.getId());
	  		    	returnResult.setUser(user1);
	  		    	returnResult.setSessionid(sessionid);
	  		    	returnResult.setValue("用户绑定过手机号");
			  }else{
				  returnResult.setKey("error");
				  returnResult.setCode("250");
	  		      returnResult.setValue("用户未绑定过手机号");
			  }
		  }else if(type.equals("2")){
			  List<PersonalUser>	users= personalUserRepository.findUserByqqopenid(openid);
			  if(users.size()>0){
				  if(users.get(0).getUsername()!=null){
						String ss=jedis.get(users.get(0).getUsername());
						if(ss==null){
							jedis.set(users.get(0).getUsername(), sessionid+",");
						}else{
							jedis.set(users.get(0).getUsername(), ss+sessionid+",");
						}
						jedis.disconnect();
				    }
	  		    	users.get(0).setQqnickname(nickname);
	  		    	users.get(0).setQqportrait(portriname);
	  		    	PersonalUser user=	personalUserRepository.save(users.get(0));
	  		    	returnResult.setKey("success");
	  		    	returnResult.setCode("200");
	  		    	Uservo  user1=new Uservo();
	  		    	user1.setUsername(user.getUsername());
	  		    	user1.setPassword(user.getPassword());
	  		    	user1.setWechatnickname(user.getWechatnickname());
	  		    	user1.setWechatopenid(user.getWechatopenid());
	  		    	user1.setWechatportrait(user.getWechatportrait());
	  		    	user1.setWeibonickname(user.getWeibonickname());
	  		    	user1.setWeiboportrait(user.getWeiboportrait());
	  		    	user1.setWeibouuid(user.getWeibouuid());
	  		    	user1.setQqnickname(user.getQqnickname());
	  		    	user1.setQqopenid(user.getQqopenid());
	  		    	user1.setQqportrait(user.getQqportrait());
	  		    	user1.setId(user.getId());
	  		    	returnResult.setUser(user1);
	  		    	returnResult.setSessionid(sessionid);
	  		    	returnResult.setValue("用户绑定过手机号");
			  }else{
				  returnResult.setKey("error");
				  returnResult.setCode("250");
	  		      returnResult.setValue("用户未绑定过手机号");
			  }
			  
		  }else if(type.equals("3")){
			  List<PersonalUser>	users= personalUserRepository.findUserByWeibouuid(openid);
			  if(users.size()>0){
				  if(users.get(0).getUsername()!=null){
						String ss=jedis.get(users.get(0).getUsername());
						if(ss==null){
							jedis.set(users.get(0).getUsername(), sessionid+",");
						}else{
							jedis.set(users.get(0).getUsername(), ss+sessionid+",");
						}
						jedis.disconnect();
				    }
	  		    	users.get(0).setWeibonickname(nickname);
	  		    	users.get(0).setWeiboportrait(portriname);
	  		    	PersonalUser user=personalUserRepository.save(users.get(0));
	  		    	returnResult.setKey("success");
	  		    	returnResult.setCode("200");
	  		    	Uservo  user1=new Uservo();
	  		    	user1.setUsername(user.getUsername());
	  		    	user1.setPassword(user.getPassword());
	  		    	user1.setWechatnickname(user.getWechatnickname());
	  		    	user1.setWechatopenid(user.getWechatopenid());
	  		    	user1.setWechatportrait(user.getWechatportrait());
	  		    	user1.setWeibonickname(user.getWeibonickname());
	  		    	user1.setWeiboportrait(user.getWeiboportrait());
	  		    	user1.setWeibouuid(user.getWeibouuid());
	  		    	user1.setQqnickname(user.getQqnickname());
	  		    	user1.setQqopenid(user.getQqopenid());
	  		    	user1.setQqportrait(user.getQqportrait());
	  		    	user1.setId(user.getId());
	  		    	returnResult.setUser(user1);
	  		    	returnResult.setSessionid(sessionid);
	  		    	returnResult.setValue("用户绑定过手机号");
			  }else{
				  returnResult.setKey("error");
				  returnResult.setCode("250");
	  		      returnResult.setValue("用户未绑定过手机号");
			  }
		  }
	  }else{
		  returnResult.setKey("error");
		  returnResult.setCode("251");
		      returnResult.setValue("openid不能为空");
	  }
    	return returnResult;
    }
   
   /**
	  * @param openid           String 类型    ：        微信   微博  qq 的openid
	   * @param type             String 类型     :  1:微信  3：微博  2：qq
	   * @param nickname         String 类型     :  昵称
	   * @param portriname       String 类型     :  头像存储地址
	   * @param phone           String 类型     :   手机号
	   * @return
	   */
  @Transactional  
    public  ApprReturn thirdLoginforphone(String  openid,String type,String phone,String nickname,String portriname){
    	ApprReturn  returnResult=new ApprReturn();
		  String mark="0";
		  if(phone!=null&&!phone.equals("")){
			  if(type.equals("1")){
				  List<PersonalUser>	users= personalUserRepository.findUsername(phone);
				  if(users.size()>0){
					    if(users.get(0).getWechatopenid()!=null&&!users.get(0).getWechatopenid().equals("")){
					    	if(users.get(0).getWechatopenid().equals(openid)){
					    		    users.get(0).setWechatnickname(nickname);
					  		    	users.get(0).setWechatportrait(portriname);
					  		    	users.get(0).setWechatopenid(openid);
					  		    	PersonalUser user=	personalUserRepository.save(users.get(0));
					  		    	returnResult.setKey("success");
					  		    	returnResult.setCode("201");
					  		    	Uservo  user1=new Uservo();
					  		    	user1.setUsername(user.getUsername());
					  		    	user1.setPassword(user.getPassword());
					  		    	user1.setWechatnickname(user.getWechatnickname());
					  		    	user1.setWechatopenid(user.getWechatopenid());
					  		    	user1.setWechatportrait(user.getWechatportrait());
					  		    	user1.setWeibonickname(user.getWeibonickname());
					  		    	user1.setWeiboportrait(user.getWeiboportrait());
					  		    	user1.setWeibouuid(user.getWeibouuid());
					  		    	user1.setQqnickname(user.getQqnickname());
					  		    	user1.setQqopenid(user.getQqopenid());
					  		    	user1.setQqportrait(user.getQqportrait());
					  		    	user1.setId(user.getId());
					  		    	returnResult.setUser(user1);
					  		    	returnResult.setValue("用户绑定过手机号");
					    	}else{
					    		returnResult.setKey("error");
				  		    	returnResult.setCode("202");
				  		    	returnResult.setValue("该手机号已绑定三方平台，请您使用新的手机号进行绑定!");
					    	}
					    }else{
					    	users.get(0).setWechatnickname(nickname);
			  		    	users.get(0).setWechatportrait(portriname);
			  		    	users.get(0).setWechatopenid(openid);
			  		    	PersonalUser user=	personalUserRepository.save(users.get(0));
			  		    	returnResult.setKey("success");
			  		    	returnResult.setCode("201");
			  		    	Uservo  user1=new Uservo();
			  		    	user1.setUsername(user.getUsername());
			  		    	user1.setPassword(user.getPassword());
			  		    	user1.setWechatnickname(user.getWechatnickname());
			  		    	user1.setWechatopenid(user.getWechatopenid());
			  		    	user1.setWechatportrait(user.getWechatportrait());
			  		    	user1.setWeibonickname(user.getWeibonickname());
			  		    	user1.setWeiboportrait(user.getWeiboportrait());
			  		    	user1.setWeibouuid(user.getWeibouuid());
			  		    	user1.setQqnickname(user.getQqnickname());
			  		    	user1.setQqopenid(user.getQqopenid());
			  		    	user1.setQqportrait(user.getQqportrait());
			  		    	user1.setId(user.getId());
			  		    	returnResult.setUser(user1);
			  		    	returnResult.setValue("用户绑定过手机号");
					    }
					   
				  }else{
					  mark="1";
					  PersonalUser personalUser=new PersonalUser();
					  personalUser.setWechatnickname(nickname);
					  personalUser.setWechatportrait(portriname);
					  personalUser.setWechatopenid(openid);
					  personalUser.setUsername(phone);
					  personalUser.setCreateTime(new Date());
	            	  personalUser.setCreateType("2");
	            	  personalUser.setLastLandTime(new Date());
					  PersonalUser user=	personalUserRepository.save(personalUser);
					  /******优惠券逻辑*******/
					  if(mark.equals("1")){
			        		personalUserCouponService.savePersonalUserCoupons(user);
			        	}
		  		    	PersonalUserLandLog landLog=personalUserDao.findByLandLog(phone, "2");
		    			if(landLog==null){
		    				landLog=new PersonalUserLandLog();
		    				landLog.setUsername(user.getUsername());
		        			landLog.setLandType("2");
		        			landLog.setLandCount(1);
		    			}else{
		    				landLog.setLandCount(landLog.getLandCount()+1);
		    			}
		    			landLog.setLandTime(new Date());
		    			personalUserLandLogRepository.save(landLog);
		    			
			  		    Uservo  user1=new Uservo();
		  		    	user1.setUsername(user.getUsername());
		  		    	user1.setPassword(user.getPassword());
		  		    	user1.setWechatnickname(user.getWechatnickname());
		  		    	user1.setWechatopenid(user.getWechatopenid());
		  		    	user1.setWechatportrait(user.getWechatportrait());
		  		    	user1.setWeibonickname(user.getWeibonickname());
		  		    	user1.setWeiboportrait(user.getWeiboportrait());
		  		    	user1.setWeibouuid(user.getWeibouuid());
		  		    	user1.setQqnickname(user.getQqnickname());
		  		    	user1.setQqopenid(user.getQqopenid());
		  		    	user1.setQqportrait(user.getQqportrait());
		  		    	user1.setId(user.getId());
	  		    	  returnResult.setKey("success");
		  		      returnResult.setCode("200");
	  		    	  returnResult.setUser(user1);
		  		      returnResult.setValue("绑定成功");
				  }
			  }else if(type.equals("2")){
				  List<PersonalUser>	users= personalUserRepository.findUsername(phone);
				  if(users.size()>0){
					   if(users.get(0).getQqopenid()!=null&&!users.get(0).getQqopenid().equals("")){
						   if(users.get(0).getQqopenid().equals(openid)){
							   users.get(0).setQqnickname(nickname);
				  		    	users.get(0).setQqportrait(portriname);
				  		    	users.get(0).setQqopenid(openid);
				  		    	PersonalUser user=	personalUserRepository.save(users.get(0));
				  		    	returnResult.setKey("success");
				  		    	returnResult.setCode("201");
				  		    	Uservo  user1=new Uservo();
				  		    	user1.setUsername(user.getUsername());
				  		    	user1.setPassword(user.getPassword());
				  		    	user1.setWechatnickname(user.getWechatnickname());
				  		    	user1.setWechatopenid(user.getWechatopenid());
				  		    	user1.setWechatportrait(user.getWechatportrait());
				  		    	user1.setWeibonickname(user.getWeibonickname());
				  		    	user1.setWeiboportrait(user.getWeiboportrait());
				  		    	user1.setWeibouuid(user.getWeibouuid());
				  		    	user1.setQqnickname(user.getQqnickname());
				  		    	user1.setQqopenid(user.getQqopenid());
				  		    	user1.setQqportrait(user.getQqportrait());
				  		    	user1.setId(user.getId());
				  		    	returnResult.setUser(user1);
				  		    	returnResult.setValue("用户绑定过手机号");
						   }else{
							    returnResult.setKey("error");
				  		    	returnResult.setCode("202");
				  		    	returnResult.setValue("该手机号已绑定三方平台，请您使用新的手机号进行绑定!");
						   }
					   }else{
						   users.get(0).setQqnickname(nickname);
			  		    	users.get(0).setQqportrait(portriname);
			  		    	users.get(0).setQqopenid(openid);
			  		    	PersonalUser user=	personalUserRepository.save(users.get(0));
			  		    	returnResult.setKey("success");
			  		    	returnResult.setCode("201");
			  		    	Uservo  user1=new Uservo();
			  		    	user1.setUsername(user.getUsername());
			  		    	user1.setPassword(user.getPassword());
			  		    	user1.setWechatnickname(user.getWechatnickname());
			  		    	user1.setWechatopenid(user.getWechatopenid());
			  		    	user1.setWechatportrait(user.getWechatportrait());
			  		    	user1.setWeibonickname(user.getWeibonickname());
			  		    	user1.setWeiboportrait(user.getWeiboportrait());
			  		    	user1.setWeibouuid(user.getWeibouuid());
			  		    	user1.setQqnickname(user.getQqnickname());
			  		    	user1.setQqopenid(user.getQqopenid());
			  		    	user1.setQqportrait(user.getQqportrait());
			  		    	user1.setId(user.getId());
			  		    	returnResult.setUser(user1);
			  		    	returnResult.setValue("用户绑定过手机号");
					   }
					    
				  }else{
					  mark="1";
					  PersonalUser personalUser=new PersonalUser();
					  personalUser.setQqnickname(nickname);
					  personalUser.setQqportrait(portriname);
					  personalUser.setQqopenid(openid);
					  personalUser.setUsername(phone);
					  personalUser.setCreateTime(new Date());
	            	  personalUser.setCreateType("2");
	            	  personalUser.setLastLandTime(new Date());
					  PersonalUser user=	personalUserRepository.save(personalUser);
					 /******优惠券逻辑*******/
					  if(mark.equals("1")){
			        		personalUserCouponService.savePersonalUserCoupons(user);
			        	}
		  		    	PersonalUserLandLog landLog=personalUserDao.findByLandLog(phone, "2");
		    			if(landLog==null){
		    				landLog=new PersonalUserLandLog();
		    				landLog.setUsername(user.getUsername());
		        			landLog.setLandType("2");
		        			landLog.setLandCount(1);
		    			}else{
		    				landLog.setLandCount(landLog.getLandCount()+1);
		    			}
		    			landLog.setLandTime(new Date());
		    			personalUserLandLogRepository.save(landLog);
		    			
			  		    Uservo  user1=new Uservo();
		  		    	user1.setUsername(user.getUsername());
		  		    	user1.setPassword(user.getPassword());
		  		    	user1.setWechatnickname(user.getWechatnickname());
		  		    	user1.setWechatopenid(user.getWechatopenid());
		  		    	user1.setWechatportrait(user.getWechatportrait());
		  		    	user1.setWeibonickname(user.getWeibonickname());
		  		    	user1.setWeiboportrait(user.getWeiboportrait());
		  		    	user1.setWeibouuid(user.getWeibouuid());
		  		    	user1.setQqnickname(user.getQqnickname());
		  		    	user1.setQqopenid(user.getQqopenid());
		  		    	user1.setQqportrait(user.getQqportrait());
		  		    	user1.setId(user.getId());
		  		    	returnResult.setKey("success");
			  		    returnResult.setCode("200");
		  		    	returnResult.setUser(user1);
		  		      returnResult.setValue("绑定成功");
				  }
			  }else if(type.equals("3")){
				  List<PersonalUser>	users= personalUserRepository.findUsername(phone);
				  if(users.size()>0){
					   if(users.get(0).getWeibouuid()!=null&&!users.get(0).getWeibouuid().equals("")){
						  if(users.get(0).getWeibouuid().equals(openid)){
							  users.get(0).setWeibonickname(nickname);
				  		    	users.get(0).setWeiboportrait(portriname);
				  		    	users.get(0).setWeibouuid(openid);
				  		    	PersonalUser user=	personalUserRepository.save(users.get(0));
				  		    	returnResult.setKey("success");
				  		    	returnResult.setCode("201");
				  		    	Uservo  user1=new Uservo();
				  		    	user1.setUsername(user.getUsername());
				  		    	user1.setPassword(user.getPassword());
				  		    	user1.setWechatnickname(user.getWechatnickname());
				  		    	user1.setWechatopenid(user.getWechatopenid());
				  		    	user1.setWechatportrait(user.getWechatportrait());
				  		    	user1.setWeibonickname(user.getWeibonickname());
				  		    	user1.setWeiboportrait(user.getWeiboportrait());
				  		    	user1.setWeibouuid(user.getWeibouuid());
				  		    	user1.setQqnickname(user.getQqnickname());
				  		    	user1.setQqopenid(user.getQqopenid());
				  		    	user1.setQqportrait(user.getQqportrait());
				  		    	user1.setId(user.getId());
				  		    	returnResult.setUser(user1);
				  		    	returnResult.setValue("用户绑定过手机号"); 
						  }else{
							    returnResult.setKey("error");
				  		    	returnResult.setCode("202");
				  		    	returnResult.setValue("该手机号已绑定三方平台，请您使用新的手机号进行绑定!");
						  } 
					   }else{
						   users.get(0).setWeibonickname(nickname);
			  		    	users.get(0).setWeiboportrait(portriname);
			  		    	users.get(0).setWeibouuid(openid);
			  		    	PersonalUser user=	personalUserRepository.save(users.get(0));
			  		    	returnResult.setKey("success");
			  		    	returnResult.setCode("201");
			  		    	Uservo  user1=new Uservo();
			  		    	user1.setUsername(user.getUsername());
			  		    	user1.setPassword(user.getPassword());
			  		    	user1.setWechatnickname(user.getWechatnickname());
			  		    	user1.setWechatopenid(user.getWechatopenid());
			  		    	user1.setWechatportrait(user.getWechatportrait());
			  		    	user1.setWeibonickname(user.getWeibonickname());
			  		    	user1.setWeiboportrait(user.getWeiboportrait());
			  		    	user1.setWeibouuid(user.getWeibouuid());
			  		    	user1.setQqnickname(user.getQqnickname());
			  		    	user1.setQqopenid(user.getQqopenid());
			  		    	user1.setQqportrait(user.getQqportrait());
			  		    	user1.setId(user.getId());
			  		    	returnResult.setUser(user1);
			  		    	returnResult.setValue("用户绑定过手机号");  
					   }
					   
				  }else{
					  mark="1";
					  PersonalUser personalUser=new PersonalUser();
					  personalUser.setWeibonickname(nickname);
					  personalUser.setWeiboportrait(portriname);
					  personalUser.setWeibouuid(openid);
					  personalUser.setUsername(phone);
					  personalUser.setCreateTime(new Date());
	            	  personalUser.setCreateType("2");
	            	  personalUser.setLastLandTime(new Date());
					  PersonalUser user=	personalUserRepository.save(personalUser);
					  /******优惠券逻辑*******/
					  if(mark.equals("1")){
			        		personalUserCouponService.savePersonalUserCoupons(user);
			        	}
		  		    	PersonalUserLandLog landLog=personalUserDao.findByLandLog(phone, "2");
		    			if(landLog==null){
		    				landLog=new PersonalUserLandLog();
		    				landLog.setUsername(user.getUsername());
		        			landLog.setLandType("2");
		        			landLog.setLandCount(1);
		    			}else{
		    				landLog.setLandCount(landLog.getLandCount()+1);
		    			}
		    			landLog.setLandTime(new Date());
		    			personalUserLandLogRepository.save(landLog);
		    			
			  		    Uservo  user1=new Uservo();
		  		    	user1.setUsername(user.getUsername());
		  		    	user1.setPassword(user.getPassword());
		  		    	user1.setWechatnickname(user.getWechatnickname());
		  		    	user1.setWechatopenid(user.getWechatopenid());
		  		    	user1.setWechatportrait(user.getWechatportrait());
		  		    	user1.setWeibonickname(user.getWeibonickname());
		  		    	user1.setWeiboportrait(user.getWeiboportrait());
		  		    	user1.setWeibouuid(user.getWeibouuid());
		  		    	user1.setQqnickname(user.getQqnickname());
		  		    	user1.setQqopenid(user.getQqopenid());
		  		    	user1.setQqportrait(user.getQqportrait());
		  		    	user1.setId(user.getId());
		  		    	returnResult.setKey("success");
			  		    returnResult.setCode("200");
		  		    	returnResult.setUser(user1);
		  		        returnResult.setValue("绑定成功");
				  }
			  }
			  
		  }else{
			  returnResult.setKey("error");
			  returnResult.setCode("250");
		      returnResult.setValue("手机号不可为空");
		  }
    	return returnResult;
    }
    
  public    ApprReturn    thirdLoginisExist(String type,String phone){
	  ApprReturn  returnResult=new ApprReturn();
	  List<PersonalUser>	users= personalUserRepository.findUsername(phone);
	  if(users.size()>0){
		  if(type.equals("1")){
			  if((users.get(0).getQqopenid()==null||users.get(0).getQqopenid().equals(""))&&(users.get(0).getWeibouuid()==null||users.get(0).getWeibouuid().equals(""))){
				  returnResult.setKey("success");
				  returnResult.setCode("200");
			      returnResult.setValue("该手机号没有绑定过其他第三方平台");
			  }else{
				  returnResult.setKey("success");
				  returnResult.setCode("201");
			      returnResult.setValue("该手机号已绑定过其他第三方平台");
			  }
		  }else if(type.equals("2")){
			  if((users.get(0).getWechatopenid()==null||users.get(0).getWechatopenid().equals(""))&&(users.get(0).getWeibouuid()==null||users.get(0).getWeibouuid().equals(""))){
				  returnResult.setKey("success");
				  returnResult.setCode("200");
			      returnResult.setValue("该手机号没有绑定过其他第三方平台");
			  }else{
				  returnResult.setKey("success");
				  returnResult.setCode("201");
			      returnResult.setValue("该手机号已绑定过其他第三方平台");
			  }
		  }else if(type.equals("3")){
			 if((users.get(0).getWechatopenid()==null||users.get(0).getWechatopenid().equals(""))&&(users.get(0).getQqopenid()==null||users.get(0).getQqopenid().equals(""))){
				  returnResult.setKey("success");
				  returnResult.setCode("200");
			      returnResult.setValue("该手机号没有绑定过其他第三方平台");
			  }else{
				  returnResult.setKey("success");
				  returnResult.setCode("201");
			      returnResult.setValue("该手机号已绑定过其他第三方平台"); 
			  }
		  }
	  }else{
		  returnResult.setKey("error");
		  returnResult.setCode("250");
	      returnResult.setValue("没有绑定过手机号");
	  }
	  return returnResult;
	  
  }
  
  @Transactional
	public ReturnResult sendAPPVeryMessage(String phone) throws Exception {
	     
		return personalCodeService.sendAPPVeryMessage(phone);
	}
  
  @Override
	public String getUserNameById(String userid) {
		return personalUserRepository.findUserNameByUserid(userid);

	}
    
}
